import zhvalues from './zh';
import enValues from './en';
import zhTWValues from './zh-TW';
import {R} from '../index';

class Resouce {
  valueString(key: string, defaultValue = '') {
    let result = this.getString(key);
    //没有远程资源，拿相应的资源
    if (result) {
      return result;
    }
    //本地没有，拿默认值
    if (defaultValue) {
      return defaultValue;
    }
    if (!key) {
      return defaultValue;
    }
    //都没有，再去中文里取一下娄底

    return zhvalues[key] ? zhvalues[key] : '';
  }

  getString(key: string) {
    let resource = zhvalues;
    if (!key) {
      return null;
    }
    if (R.LangueKey == 'zh') {
      resource = zhvalues;
    } else if (R.LangueKey == 'zh-TW') {
      resource = zhTWValues;
    } else if (R.LangueKey.indexOf('en') >= 0) {
      resource = enValues;
    } else {
      resource = zhvalues;
    }
    return resource[key];
  }
}

const resource = new Resouce();

export default function valueString(key: string, defaultValue = '') {
  return resource.valueString(key, defaultValue);
}
